{{define "system/system_user_add.html"}}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加操作员用户</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
{{template "include/styleRefer.html"}}
    <link rel="stylesheet" href="/res/plugins/iCheck/all.css">
{{template "include/scriptRefer.html"}}
    <script src="/res/plugins/iCheck/icheck.min.js"></script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
{{template "mainHeader.html"}}
{{template "nav.html"}}
    <div class="content-wrapper">
    {{template "contentHeader.html"}}
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <form class="form-horizontal" id="systemUserAddForm">
                        <div class="box box-info" style="box-shadow: none;margin-bottom: 0;">
                            <div class="box-header with-border">
                                <h3 class="box-title">添加管理员账号</h3>
                            </div>
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="userName" class="col-sm-2 control-label">姓名：</label>
                                    <div class="col-sm-4">
                                        <input type="text" name="name" class="form-control" id="name"
                                               placeholder="姓名">
                                    </div>

                                    <label for="idCard" class="col-sm-2 control-label">所属机构：</label>
                                    <div class="col-sm-4">
                                        <select class="form-control" id="organCode" name="organCode">
                                            <optgroup label=""></optgroup>
                                        </select>
                                        <input type="hidden" name="organName" id="organName" value=""/>
                                    </div>
                                </div>
                                <div class="form-group">

                                    <label for="account" class="col-sm-2 control-label">账号:</label>
                                    <div class="col-sm-4">
                                        <input type="text" name="account" class="form-control" id="account"
                                               placeholder="账号">
                                    </div>
                                    <label for="password" class="col-sm-2 control-label">密码:</label>
                                    <div class="col-sm-4">
                                        <input type="password" name="password" class="form-control" id="password"
                                               placeholder="密码">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-sm-2">角色：</label>
                                    <div class="radio col-sm-4">
                                        <input type="radio" name="role" value="0" class="minimal" checked>&nbsp;操作员&nbsp;&nbsp;
                                        {{/*<input type="radio" name="role" value="1" class="minimal">&nbsp;管理员*/}}
                                    </div>
                                </div>

                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn btn-info middleBtn" id="systemUserAddSubmitBtn">提交
                                </button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </section>
    </div>
</div>
<link rel="stylesheet" href="/res/plugins/toastr/toastr.min.css">
<script src="/res/plugins/toastr/toastr.min.js"></script>
<script>
    $(function () {
        $('input[type="radio"].minimal').iCheck({
            radioClass: 'iradio_minimal-blue'
        });
        $('#systemUserAddSubmitBtn').click(addSystemUser);
        $('#organCode').change(setOrganName);
        let organs ={{.organs}};
        $.each(organs, function (index, val) {
            let parent = val;
            let children = val.children;
            let optionGroup = $("<optgroup label='" + val.organName + "'></optgroup>");
            $.each(children, function (index2, val2) {
                let option = $("<option value='" + val2.organCode + "'>" + val2.organName + "</option>")
                optionGroup.append(option);
            });
            $("#organCode").append(optionGroup);
        });
        setOrganName();
    });

    function setOrganName() {
        let organName = $("#organCode option:selected").text();
        $("#organName").val(organName);
        //alert(organName);
    }

    function addSystemUser() {
        let d = {};
        let t = $('#systemUserAddForm').serializeArray();
        $.each(t, function () {
            d[this.name] = this.value;
        });
        if (d["account"]=="" || d["password"]==""){
            toastr.warning("账户名或者密码不能为空", '提示', {
                "progressBar": true,
                "positionClass": "toast-top-center",
                "timeOut": "5000",
                "closeButton": true
            });
            return false;
        }
        $.ajax({
                    url: '/system/user/saveOrUpdateUser',
                    type: 'POST',
                    data: JSON.stringify(d),
                    contentType: "application/json;charset=utf-8",
                    success: function (resp) {
                        toastr.success(resp.msg, '', {"positionClass": "toast-top-center"});
                        if (resp.code == 0) {
                            window.location.reload();
                        }
                    }
                }
        );
    }
</script>
</body>
</html>
{{end}}